package com.quick.develop.flowable.framework.cmd;

import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.service.HistoricTaskService;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

/**
 * @author junyuan.liu
 * @description:
 * @date 2022/8/14 13:35
 */
public class SetHistoricTaskCategoryCmd extends NeedsActiveTaskCmd<Void> {


    private static final long serialVersionUID = -4021809982707637875L;

    public SetHistoricTaskCategoryCmd(String taskId) {
        super(taskId);
    }

    @Override
    protected Void execute(CommandContext commandContext, TaskEntity taskEntity) {
        HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService(commandContext);
        HistoricTaskInstanceEntity historicTask = historicTaskService.getHistoricTask(taskId);
        historicTask.setCategory(taskEntity.getCategory());
        historicTaskService.updateHistoricTask(historicTask, false);

        return null;
    }
}
